package PTA;

import java.util.Scanner;

public class PTA_7_55 {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String S = scan.next();
        if(S.matches("[A-Z]"+"[a-z]{3}"+"\\d{3}"))
            System.out.println(S + "合法");
        else
         System.out.println(S + "不合法");
    }
}
